package com.aaron.kjviewutils;

import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.os.Handler;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.aaron.kjviewutils.glide.GlideCircleTransform;
import com.bumptech.glide.Glide;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 作者：Aaron on 2017/2/14 15:11
 * 邮箱：kaijin.fang@edianniu.com
 */
public class WeekDataFilpperAdapter extends BaseAdapter {

    private Activity aty;
    private List<MainBean.MainSub.Future> datas;
    private Handler mHandler;
    private Context context;
    private Resources resources;

    public WeekDataFilpperAdapter(Activity aty, Context context, Handler mHandler, List<MainBean.MainSub.Future> datas)
    {
        this.aty = aty;
        this.context = context;
        this.mHandler = mHandler;
        this.datas = datas;
        this.resources = resources;
    }

    @Override
    public int getCount() {
        return  null==datas?0:datas.size();
    }

    @Override
    public Object getItem(int position) {
        return (null==datas||datas.isEmpty())?null:datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;
        if (convertView == null)
        {
            convertView = View.inflate(context, R.layout.item_week_layout, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }
        else
        {
            holder = (ViewHolder) convertView.getTag();
        }
        if(null!=datas&&!datas.isEmpty()&&null!=datas.get(position))
        {
            MainBean.MainSub.Future future = datas.get(position);
            String logoUrl = null;
            if("阵雨".equals(future.dayTime))
            {
                logoUrl = "http://www.zsqx.com/weather/images/warming_logo/03.gif";
            }
            else if("晴".equals(future.dayTime))
            {
                logoUrl = "http://www.fuhaodq.com/d/file/qqtx/20160727/xcjjqimh245xo0.jpg";
            }
            else if("阴".equals(future.dayTime))
            {
                logoUrl = "http://img1.cache.netease.com/catchpic/7/7D/7D1D73601155FB75386C39C1E7A08A67.jpg";
            }
            else
            {
                logoUrl = "http://img24.nipic.com/20110419/7191923_151745284108_1.jpg";
            }
            Glide.with(aty).load(logoUrl).transform(new GlideCircleTransform(aty)).dontAnimate().placeholder(R.mipmap.ic_launcher).into(holder.weatherLogo);
            holder.dateText.setText((TextUtils.isEmpty(future.date) ? "未知" : future.date));
            holder.weekText.setText((TextUtils.isEmpty(future.week)?"未知":future.week));
            holder.weatherType.setText((TextUtils.isEmpty(future.dayTime)?"未知":future.dayTime));
            holder.temperature.setText((TextUtils.isEmpty(future.temperature)?"未知":future.temperature));
            holder.wind.setText((TextUtils.isEmpty(future.wind)?"未知":future.wind));
        }
        return convertView;
    }

    class ViewHolder
    {
        public ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
        @Bind(R.id.weatherLogo)
        ImageView weatherLogo;
        @Bind(R.id.dateText)
        TextView dateText;
        @Bind(R.id.weekText)
        TextView weekText;
        @Bind(R.id.weatherType)
        TextView weatherType;
        @Bind(R.id.temperature)
        TextView temperature;
        @Bind(R.id.wind)
        TextView wind;
    }
}
